/** 数据操作同步函数 */
import {
  COUNTER_INCREMENT,
  COUNTER_DECREMENT
} from './counterType'


// counterReducer()函数：数据操作函数
// 参数1：state数据
// 参数2：creator，操作对象，格式{type: 操作类型， data: 操作数据}
function counterReducer(state = 0, creator) {
  switch (creator.type) {
    case COUNTER_INCREMENT:

      state += creator.data
      console.log("增加数据", state)
      return state

    case COUNTER_DECREMENT:

      state -= creator.data
      console.log("减少数据", state)
      return state

    default:
      console.log("读取数据", state)
      return state
  }
}

export default counterReducer